package com.tricode.ile.training.task.sl275.lab6;

public class CheckingAccount extends Account {

    private double overdraftAmount;

    public CheckingAccount(double initBalance){
        super(initBalance);
    }

    /**
     * Creates a new instance of Account
     */
    public CheckingAccount(double initBalance, double overDraftAmount) {
        this(initBalance);
        this.overdraftAmount = overDraftAmount;
    }

    public double getOverdraftAmount() {
        return overdraftAmount;
    }

    public void setOverdraftAmount(double overdraftAmount) {
        this.overdraftAmount = overdraftAmount;
    }

    public boolean withdraw(double amount) {
        if(amount > (getBalance()+overdraftAmount)){
           return false;
        } else {
            double difference = amount - getBalance();
            if(amount <= getBalance()) {
               super.withdraw(amount);
            }
           if(difference <= overdraftAmount) {
               this.overdraftAmount -= difference;
               return true;
           }
        }
        return false;
    }
}
